package com.chixing.day08_interface.work;

import java.util.ArrayList;

public class AllOrder implements Order{
    //由于订单数量不能确定，所以这边使用ArrayList
    //由于只需要一个数组存放，所以用static修饰
    public static ArrayList<AllOrder> OrderArray = new ArrayList<>();
    private Integer number;

    public AllOrder(Integer number) {
        this.number = number;
    }

    public AllOrder() {
    }

    @Override
    public void splitOrder(AllOrder order) {
        //判断订单类型
        if (order instanceof PersonOrder){
            while (order.getNumber() >= 1000){
                //每出现满1000订单创建一个对象 存入arraylist
                PersonOrder personOrder = new PersonOrder(((PersonOrder) order).getUsername());
                personOrder.setNumber(1000);
                OrderArray.add(personOrder);
                order.setNumber(order.getNumber()-1000);
            }
            if (order.getNumber()!=0) {
                PersonOrder personOrder = new PersonOrder(((PersonOrder) order).getUsername());
                personOrder.setNumber(order.getNumber());
                OrderArray.add(personOrder);
            }
        }
        if (order instanceof CompanyOrder){
            while (order.getNumber() >= 1000){
                //每出现满1000订单创建一个对象 存入arraylist
                CompanyOrder companyOrder = new CompanyOrder(((CompanyOrder) order).getCompanyName());
                companyOrder.setNumber(1000);
                OrderArray.add(companyOrder);
                order.setNumber(order.getNumber()-1000);
            }
            if (order.getNumber()!=0) {
                CompanyOrder companyOrder = new CompanyOrder(((CompanyOrder) order).getCompanyName());
                companyOrder.setNumber(order.getNumber());
                OrderArray.add(companyOrder);
            }
        }
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    @Override
    public String toString() {
        return "AllOrder{" +
                "number=" + number +
                '}';
    }
}
